{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Comrprs"

// By ArtemQa146

const
    RepairMan_Up = 31@
    Process = 30@
    Screw = 29@
    Spanner = 28@
    ToolBox = 27@
    Screw_Render = 26@
    Spanner_Render = 25@
    Rope = 24@
    Rope_Render = 23@
    Ped_ID = 22@
    Time_Weather = 21@
    Time_Work = 80000
    Time_Out = 30000
end

0085: Spanner = 0@ // (int)
0085: Screw = 1@ // (int)
0085: ToolBox = 2@ // (int)
0085: Rope = 3@ // (int)
0085: Ped_ID = 4@ // (int)

while true
wait 50
    if
        player.Defined(0)
    then

    //  
    04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.0 20.0 0.0
    0AA7: call_function_return 0x5693F0 num_params 9 pop 9 0 0 0 0 1 0 60.0 1@v 1308 5@
    if
        5@ > 0
    then
        //       
        0EEE: get_entity_coordinates 5@ store_to 1@ 2@ 3@
        if 
            not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1@ 2@ 3@ radius 30.0
        then

        3@ += 7.8 //    ,    
        0D4E: 6@ = read_struct 5@ offset 0x14 size 4 //iao?eoa
        if
            6@ > 0
        then
            //   
            6@ += 0x20 //CMatrix -> top CVector
            0A8D: 7@ = read_memory 6@ size 4 virtual_protect 0 // X
            6@ += 0x4  //CVector y
            0A8D: 8@ = read_memory 6@ size 4 virtual_protect 0 // Y
            6@ += 0x4  //CVector Z
            0A8D: 9@ = read_memory 6@ size 4 virtual_protect 0 // Z
            if and
                7@ == 0.0
                8@ == 0.0
                9@ == 1.0
            then
            
            repeat
            wait 0
            04ED: load_animation  "PedEventsMod"
            until 04EE:   animation "PedEventsMod" loaded
        
                model.Load(Ped_ID)
                if
                    not model.Available(Ped_ID)
                then
                    repeat
                    wait 0
                    model.Load(Ped_ID)
                    until model.Available(Ped_ID)
                end
                038B: load_requested_models
                1@ -= 0.2
                009A: RepairMan_Up = create_actor_pedtype 4 model Ped_ID at 1@ 2@ 3@
                0EEE: get_entity_coordinates 5@ store_to 4@ 5@ 6@
                0E27: get_angle_from_two_coords 1@ 2@ and 4@ 5@ to 3@
                0173: set_actor RepairMan_Up Z_angle_to 3@
                model.Destroy(Ped_ID)
                0575: set_actor RepairMan_Up pinned_position 1
                0209: 0@ = random_int_in_ranges 1 4
                0AD3: 1@s = string_format "idle%d" 0@
                0812: AS_actor RepairMan_Up perform_animation 1@s IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                0E24: fix_char RepairMan_Up ground 0 brightness 1 and_fade_in 0
                0F02: create_render_object_to_char_bone_from_special RepairMan_Up special_model Spanner bone 34 offset 0 0 0 rotation 0 0 0 store_to Spanner_Render
                0F02: create_render_object_to_char_bone_from_special RepairMan_Up special_model Screw bone 24 offset 0 0 0 rotation 0 0 0 store_to Screw_Render
                0F02: create_render_object_to_char_bone_from_special RepairMan_Up special_model rope bone 51 offset 0.0 -0.06 -0.13 rotation 0 0 0 store_to Rope_Render
                0E37: set_render_object_scale Rope_Render 1.0 0.9 1.0
                0F02: create_render_object_to_char_bone_from_special RepairMan_Up special_model ToolBox bone 3 offset 0.235 0.0 0.0 rotation 0 5.0 0 store_to 0@
                0E37: set_render_object_scale 0@ 0.9 0.9 0.9
                timera = 0
                timerb = 0
                Process = 0

                    //  
                    repeat
                    wait 0
                    if
                        056D:   actor RepairMan_Up defined
                    then

                        //    
                        if
                            not locate_char_distance_to_char $PLAYER_ACTOR char RepairMan_Up radius 150.0
                        then
                            009B: destroy_actor RepairMan_Up
                            break
                        end
        

                        //  
                        0613: 0@ = actor RepairMan_Up animation 1@s time
                        if and
                            Process == 0
                            0@ > 0.9
                        then
                            0209: 0@ = random_int_in_ranges 1 4
                            0AD3: 1@s = string_format "idle%d" 0@
                            0812: AS_actor RepairMan_Up perform_animation 1@s IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                            timerb = 0
                        else
                            //    ,  
                            if and
                                Process == 0
                                timerb > 1000
                            then
                                if and
                                    not actor.Dead(RepairMan_Up)
                                    8611:   not actor RepairMan_Up performing_animation 1@s
                                then
                                    0209: 0@ = random_int_in_ranges 1 4
                                    0AD3: 1@s = string_format "idle%d" 0@
                                    0812: AS_actor RepairMan_Up perform_animation 1@s IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                                    timerb = 0
                                end
                            end
                        end

        
                        //           
                        if
                            Process == 0
                        then
                            080E: get_actor RepairMan_Up ped_event_to 0@
                            if or
                                0@ == 9
                                actor.Dead(RepairMan_Up)
                            then
                                0E31: set_render_object_visible Screw_Render 0
                                0E31: set_render_object_visible Spanner_Render 0
                                0E31: set_render_object_visible Rope_Render 0
                                0575: set_actor RepairMan_Up pinned_position 0
                                04C4: store_coords_to 1@ 2@ 3@ from_actor RepairMan_Up with_offset 0.0 -0.5 -1.0
                                00A1: put_actor RepairMan_Up at 1@ 2@ 3@
                                0687: clear_actor RepairMan_Up task
                                0812: AS_actor RepairMan_Up perform_animation "down" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1  // versionB
                                01C2: remove_references_to_actor RepairMan_Up
                                break
                            end
                        end
                        
                        
                        //  
                        if
                            Process == 0
                        then
                            gosub @Time_Weather
                            if or
                                0@ == false
                                timera > Time_Work
                            then
                                Process = 1
                                timera = 0
                                0E31: set_render_object_visible Screw_Render 0
                                0E31: set_render_object_visible Spanner_Render 0
                                0E31: set_render_object_visible Rope_Render 0
                                0575: set_actor RepairMan_Up pinned_position 0
                                04C4: store_coords_to 1@ 2@ 3@ from_actor RepairMan_Up with_offset 0.0 -0.3 -1.0
                                00A1: put_actor RepairMan_Up at 1@ 2@ 3@
                                0812: AS_actor RepairMan_Up perform_animation "down" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                            end
                        end
                            //     
                            if and
                                Process == 1
                                timera > 100
                            then
                                0575: set_actor RepairMan_Up pinned_position 1
                                Process = 2
                                timera = 0
                            end
                                // 
                                if and
                                    Process == 2
                                    timera > 400
                                then
                                    0575: set_actor RepairMan_Up pinned_position 0
                                    Process = 3
                                    timera = 0
                                    01C2: remove_references_to_actor RepairMan_Up
                                    break
                                end
                                
                    //    
                    else
                        break
                    end
                        until not player.Defined(0)
                            04EF: release_animation "PedEventsMod"
                            wait Time_Out
                            0A93: terminate_this_custom_script
                        end
                    end
                end
            end
        end
end

:Time_Weather
0@ = false
0E40: get_current_hour 1@
    if and
        1@ >= 12
        1@ < 18
        887A:   not gang_war_in_progress
    then
        0D59: get_current_weather_to 1@
        if and
            not 1@ == 8
            not 1@ == 16
        then
            0@ = true
        end
    end
return
